import { reactive } from "vue";
import Api from "@/utils/http";

const state = reactive({
  user_id: "",
  quantity: 0,
  machine_total: 0,
  machine_count: 0,
  turn_count: 0,
  manual_move_count: 0,

  paramsPopupShow: false,
  params: {
    is_machine: new Set<number>(),
    status: new Set<number>(),
  },
  list: [] as Array<{
    status: 0 | 2 | 5 | 6;
    is_first: 0 | 1;
    is_machine: 0 | 1;
    solution_name: string;
    create_datetime: string;
    result: (0 | 1 | -1)[][];
    is_exists: 1 | 2;
  }>,

  detail: {
    show: false,
    matrix: [] as (0 | 1 | -1)[][],
  },

  modal: {
    modalOk: false,
    modalNew: false,
    machine_num: 0,
    machine_first_num: 0,
    quantity: 0,
  },
});

export const initData = async () => {
  const res = await Api.get("queen/user_records/", {
    params: {
      is_machine: Array.from(state.params.is_machine).join(),
      status: Array.from(state.params.status).join(),
    },
  });
  Object.assign(state, res.count_info, { list: res.result });
};

export default state;
